<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML>
<html style='height:100%;'>
<head>
<base href="<%=basePath%>">

<title>宠物审批</title>
<link rel="stylesheet" href="css/vivo.css">
<link rel="stylesheet" href="css/bootstrap.css">
<link rel="stylesheet" href="js/bootstrap2/css/bootstrap.min.css">
<link rel="stylesheet" href="css/common.css">
<link href="js/select2/select2.min.css" type="text/css" rel="stylesheet" />
<link rel="stylesheet" type="text/css"
	href="static/p_house/house_index.css" />
<link rel="stylesheet" type="text/css"
	href="js/webuploader-0.1.5/webuploader.css" />

<script src="js/jquery-1.11.1.js"></script>
<script src="js/bootstrap2/js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/layui-v2.1.5/layui/layui.all.js"></script>
<script type="text/javascript"
	src="<%=basePath%>js/My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript" src="js/webuploader-0.1.5/webuploader.js"></script>
<script type="text/javascript" src="js/sharefunction.js"></script>
<script src="js/select2/select2.min.js"></script>
<script type="text/javascript" src="js/form.js"></script>
<!-- 图片放大 -->
<script src="js/postbird-img-glass/postbird-img-glass.js"></script>
<style>
.webuploader-container {
	position: relative;
	top: 5px;
}
</style>
<script type="text/javascript">
$(function() {
	//悬浮提示
	toolTip();
	//修改字段标记记录变量
	<c:if test="${requestScope.notPassExamine}">
		<c:set var="marks" value="原数据"/>
	</c:if>
})
</script>
<body>
	<!-- 宠物 -->
	<form class="cmxform" id="petAddForm" method="post"
		action="customer/pet/disposePet">
		<input type="hidden" id="petAdd_articleId">
		<div class="panel panel-default">
			<div class="panel-body ">
				<table cellpadding="10" cellspacing="5" class="mytable">
					<tr style="border-bottom:1px solid gray">
						<td colspan="6"><span class="style_btn">宠物信息</span></td>
					</tr>
					<tr>
						<td width="73" class="td-right">宠物名称</td>
						<td><input name="petName" id="petName" />
							<c:if test="${not empty requestScope.map.petName }"><span class="toolTip mark-msg" data-tip="${requestScope.map.petName }">
								<c:out value="${marks}"/></span>
							</c:if>
							<c:if test="${requestScope.map.petName=='' }"><span class="toolTip mark-msg"data-tip="空">
								<c:out value="${marks}"/></span>
							</c:if>
						</td>
						<td width="90" class="td-right">宠物颜色</td>
						<td><select class="js-example-basic-single" name="petColor"
							id="petColor" style="width:120px;">
								<option value="" selected="selected">请选择</option>
							</select>
							<c:if test="${not empty requestScope.map.petColor }"><span class="toolTip mark-msg" data-tip="${requestScope.map.petColor }">
								<c:out value="${marks}"/></span>
							</c:if>
							<c:if test="${requestScope.map.petColor=='' }"><span class="toolTip mark-msg"data-tip="空">
								<c:out value="${marks}"/></span>
							</c:if>
						</td>
						<td width="73" class="td-right">宠物类型</td>
						<td><select class="js-example-basic-single"
							style="width: 120px" name="petType" id="petType">
								<option value="" selected="selected">请选择</option>
							</select>
							<c:if test="${not empty requestScope.map.petType }"><span class="toolTip mark-msg" data-tip="${requestScope.map.petType }">
								<c:out value="${marks}"/></span>
							</c:if>
							<c:if test="${requestScope.map.petType=='' }"><span class="toolTip mark-msg"data-tip="空">
								<c:out value="${marks}"/></span>
							</c:if>
						</td>
					</tr>
					<tr>
						<td width="73" class="td-right">登记证</td>
						<td><input name="registerCertificate" id="registerCertificate" />
							<c:if test="${not empty requestScope.map.registerCertificate }"><span class="toolTip mark-msg" data-tip="${requestScope.map.registerCertificate }">
								<c:out value="${marks}"/></span>
							</c:if>
							<c:if test="${requestScope.map.registerCertificate=='' }"><span class="toolTip mark-msg"data-tip="空">
								<c:out value="${marks}"/></span>
							</c:if>
							 <!-- 上传按钮 -->
							<div id='filePicker_cwdjz' style="display:none;">上传</div></td>
						<td width="90" class="td-right">健康免疫证</td>
						<td><input name="healthCertificate" id="healthCertificate" />
							<c:if test="${not empty requestScope.map.healthCertificate }"><span class="toolTip mark-msg" data-tip="${requestScope.map.healthCertificate }">
								<c:out value="${marks}"/></span>
							</c:if>
							<c:if test="${requestScope.map.healthCertificate=='' }"><span class="toolTip mark-msg"data-tip="空">
								<c:out value="${marks}"/></span>
							</c:if>
							<!-- 上传按钮 -->
							<div id='filePicker_jkz' style="display:none;">上传</div></td>
						<td colspan="2"></td>
					</tr>
					<tr>
						<td colspan="3">
							<!-- 附件上传 宠物_登记证。。。--> <!-- 缩略图容器 -->
							<div id='list_cwdjz'></div>
						</td>
						<td colspan="3">
							<!-- 附件上传 宠物_健康免疫证。。。--> <!-- 缩略图容器 -->
							<div id='list_jkz'></div>
						</td>
					</tr>
				</table>
			</div>
			<!-- 专项申报 -->
		</div>
		<c:if test="${requestScope.notPassExamine}">
			<!-- 修改时添加变更说明 -->
			<div style="margin:10px;" id="approvalRemark">
				审批意见<textarea rows="3" name="approvalRemark"style="width:70%"></textarea><span style="color:red;">*</span>
			</div>
			<div style="width:100%;text-align:center; padding-top:0px">
				<button class="btn btn-danger radius my-btn"
					onclick="savePet(0)" type="button">同意</button>
				<button class="btn btn-default radius"
					onclick="savePet(1)" type="button">拒绝</button>
			</div>
		</c:if>
		<!-- 隐藏域 -->
		<div style="display:none;">
			<input name="exDataId" id="exDataId" value="${exDataId }" />
		</div>
	</form>
	<!-- 表单结束 -->
	<script type="text/javascript">
		var petFlag; //查看、编辑状态
		$(function() {
			$("#petAddForm #petColor").select2({tags : true});
			$("#petAddForm #petType").select2({tags : true});
			getFiles();
			//初始化表单
			mySubmit("petAddForm", initSavePet, petAddSuccess);
	
			//获取编辑页面数据
			initPetMsg();
		});
		//展示附件
		function getFiles() {
			var petManager = ${petManager};
			var petId = petManager.id;
			getFileListByFlag(petId, "宠物登记证",2, "#list_cwdjz",  imgPlus);
			getFileListByFlag(petId, "宠物健康免疫证",2, "#list_jkz", imgPlus);
			<c:if test="${requestScope.notPassExamine}"> 
			var fileCas= ${requestScope.caList};
			if(fileCas.length > 0){
				var cwdjz = "";//宠物登记证
				var jkz = "";//宠物健康免疫证
				for(var i=0;i<fileCas.length;i++){
					if(fileCas[i].articleId == "宠物登记证"){
						cwdjz += (","+fileCas[i].accessoryCAId);
					}else if(fileCas[i].articleId == "宠物健康免疫证"){
						jkz += (","+ fileCas[i].accessoryCAId);
					}
				}
				if(cwdjz != ""){
					getFileTempList(cwdjz.substring(1),"#list_cwdjz", imgPlus);
				}
				if(jkz != ""){
					getFileTempList(jkz.substring(1), "#list_jkz",  imgPlus);
				}
			}
			</c:if>
			
		}
		function imgPlus(data) {
			$.each(data, function(i, v) {
				//图片放大
				PostbirdImgGlass.init({
					domSelector : "#" + v.id + " img",
					animation : true,
					myDocument : window.parent.parent.parent
				});
			});
		}
		//初始化赋值
		function initPetMsg() {
			var data = ${petManager};
			var $s2 = $("#petAddForm").find("[name='petColor']");
			$s2.append("<option value=\"" + data.petColor + "\">" + data.petColor + "</option>");
			$("#petAddForm input[name='petName']").val(data.petName);
			$s2.val(data.petColor).trigger("change");
			var $s3 = $("#petAddForm").find("[name='petType']");
			$s3.append("<option value=\"" + data.petType + "\">" + data.petType + "</option>");
			$s3.val(data.petType).trigger("change");
			$("#petAddForm input[name='registerCertificate']").val(data.registerCertificate);
			$("#petAddForm input[name='healthCertificate']").val(data.healthCertificate);
			//设置只读
			$("#petAddForm").find("input").attr("readonly", true);
			$("#petAddForm").find("select,.addbtn,[type='file']").attr("disabled", true);
			$("#petAddForm div[id^='filePicker']").unbind("click").hide();
		}
	
		var optPet;
		//optEvent操作字段，0：同意 1 拒绝
		function savePet(val) {
			optPet = val;
			$("#petAddForm").submit();
		}
	
	
		function petAddSuccess(responseText) {
			layer.close(peti);
			if (responseText.success) {
				layer.alert("保存成功！", {
					offset : '20%',
					shade : [ 0.1, '#fff' ]
				}, function() {
					parent.location.reload();
					parent.parent.getPendingCount();
					parent.parent.getPendingPassCount();
					parent.parent.getPendingBackCount();
					layer.close(peti);
				});
	
			} else {
				layer.alert('保存失败！');
			}
		}
		var peti;
		function initSavePet() {
			peti = layer.load(2);
			var exDataId = '${exDataId}';
			var apId = '${apId}';
			var approvalRemark = $("#petAddForm [name='approvalRemark']").val();
			if(approvalRemark==""){
				layer.msg("审批意见不能为空");
				$("#petAddForm [name='approvalRemark']").focus();
				layer.close(peti);
				return null;
			}
			return {
				apId:apId,
				exDataId:exDataId,
				opt : optPet,
				approvalRemark:approvalRemark
			}
		}
	</script>
</body>